package com.toubutu.audio.controller;

import com.toubutu.audio.dto.CommentDto;
import com.toubutu.audio.dto.PageQueryCommentDto;
import com.toubutu.audio.dto.UserCommentDto;
import com.toubutu.audio.service.CommentService;
import com.toubutu.audio.vo.CommentItemVo;
import com.toubutu.audio.vo.CommentVo;
import com.toubutu.common.PageUtils;
import com.toubutu.common.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 戒躁
 * @since 2024-01-08
 */
@RestController
@Api(tags = "前台评论接口")
@RequestMapping("/comment")
public class CommentController {

    @Resource
    private CommentService commentService;

    @PostMapping("/page")
    @ApiOperation("分页查询视频评论数据")
    public Result<PageUtils<CommentVo>> queryVideoComment(@RequestBody PageQueryCommentDto dto){
       return Result.ok( commentService.getCommentList(dto));
    }

    @PostMapping("/reply")
    @ApiOperation("分页查询视频评论数据")
    public Result<PageUtils<CommentVo>> queryVideoReplyComment(@RequestBody PageQueryCommentDto dto){
        return Result.ok( commentService.getReplyCommentList(dto));
    }
    @PostMapping("/publish")
    @ApiOperation("发布评论")
    public Result<Void> publishComment(@RequestBody @Valid CommentDto commentDto){
        commentService.publishComment(commentDto);
        return Result.ok();
    }

    @PostMapping("/user")
    public Result<PageUtils<CommentItemVo>> getUserCommentList(@RequestBody UserCommentDto dto){
        return Result.ok(commentService.getUserCommentList(dto));
    }

    @DeleteMapping("/delete/{commentId}")
    public Result<Void> deleteComment(@PathVariable("commentId")Integer commentId){
        commentService.deleteCommentById(commentId);
        return Result.ok();
    }
}
